---
title: "表格布局"
# description: "Utilities for controlling the table layout algorithm."
description: "用于控制表格布局算法的功能类。"
features:
  responsive: true
  customizable: false
  hover: false
  focus: false
---

import plugin from 'tailwindcss/lib/plugins/tableLayout'
import { Variants } from '@/components/Variants'
import { Disabling } from '@/components/Disabling'

export const classes = { plugin }

## Auto

<!-- Use `table-auto` to allow the table to automatically size columns to fit the contents of the cell. -->
使用 `table-auto` 允许表格自动调整列的大小以适应单元格的内容。

```html emerald
<template preview>
  <table class="table-auto">
    <thead>
      <tr>
        <th class="px-4 py-2 text-emerald-600">Title</th>
        <th class="px-4 py-2 text-emerald-600">Author</th>
        <th class="px-4 py-2 text-emerald-600">Views</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Intro to CSS</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Adam</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">858</td>
      </tr>
      <tr class="bg-emerald-200">
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Adam</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">112</td>
      </tr>
      <tr>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Intro to JavaScript</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Chris</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">1,280</td>
      </tr>
    </tbody>
  </table>
</template>

<table class="**table-auto**">
  <thead>
    <tr>
      <th>Title</th>
      <th>Author</th>
      <th>Views</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Intro to CSS</td>
      <td>Adam</td>
      <td>858</td>
    </tr>
    <tr class="bg-emerald-200">
      <td>A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
      <td>Adam</td>
      <td>112</td>
    </tr>
    <tr>
      <td>Intro to JavaScript</td>
      <td>Chris</td>
      <td>1,280</td>
    </tr>
  </tbody>
</table>
```

## Fixed

<!-- Use `table-fixed` to allow the table to ignore the content and use fixed widths for columns. The width of the first row will set the column widths for the whole table. -->

<!-- You can manually set the widths for some columns and the rest of the available width will be divided evenly amongst the columns without explicit width. -->
使用 `table-fixed` 允许表格忽略内容，使用固定的列宽。第一行的宽度将设置整个表格的列宽。

您可以手动设置一些列的宽度，其余的可用宽度将被平均分配给没有明确宽度的列。

```html lightBlue
<template preview>
  <table class="table-fixed">
    <thead>
      <tr>
        <th class="w-1/2 px-4 py-2 text-light-blue-600">Title</th>
        <th class="w-1/4 px-4 py-2 text-light-blue-600">Author</th>
        <th class="w-1/4 px-4 py-2 text-light-blue-600">Views</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="border border-light-blue-500 px-4 py-2 text-light-blue-600 font-medium">Intro to CSS</td>
        <td class="border border-light-blue-500 px-4 py-2 text-light-blue-600 font-medium">Adam</td>
        <td class="border border-light-blue-500 px-4 py-2 text-light-blue-600 font-medium">858</td>
      </tr>
      <tr class="bg-light-blue-200">
        <td class="border border-light-blue-500 px-4 py-2 text-light-blue-600 font-medium">A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
        <td class="border border-light-blue-500 px-4 py-2 text-light-blue-600 font-medium">Adam</td>
        <td class="border border-light-blue-500 px-4 py-2 text-light-blue-600 font-medium">112</td>
      </tr>
      <tr>
        <td class="border border-light-blue-500 px-4 py-2 text-light-blue-600 font-medium">Intro to JavaScript</td>
        <td class="border border-light-blue-500 px-4 py-2 text-light-blue-600 font-medium">Chris</td>
        <td class="border border-light-blue-500 px-4 py-2 text-light-blue-600 font-medium">1,280</td>
      </tr>
    </tbody>
  </table>
</template>

<table class="**table-fixed**">
  <thead>
    <tr>
      <th class="w-1/2 ...">Title</th>
      <th class="w-1/4 ...">Author</th>
      <th class="w-1/4 ...">Views</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Intro to CSS</td>
      <td>Adam</td>
      <td>858</td>
    </tr>
    <tr class="bg-blue-200">
      <td>A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
      <td>Adam</td>
      <td>112</td>
    </tr>
    <tr>
      <td>Intro to JavaScript</td>
      <td>Chris</td>
      <td>1,280</td>
    </tr>
  </tbody>
</table>
```

<!-- ## Customizing -->
## 自定义

<!-- ### Variants -->
### 变体

<Variants plugin="tableLayout" />

<!-- ### Disabling -->
### 禁用

<Disabling plugin="tableLayout" />
